/**
* Appcelerator Titanium Platform
* Copyright (c) 2009-2011 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
**/
// Code is stripped-down version of Tweetanium, to expose new structure paradigm

(function(){
	S.ui = {};
	// Tabs display toggle
	S.ui.tabsHidden = false;
	
	//create a film strip like view 
	S.ui.createFilmStripView = function(_args) {
		// Root view, app views, temp container to hold the app views
		var root = Ti.UI.createView(S.combine($$.mainFilmStrip,_args)),
		views = _args.views,
		container = Ti.UI.createView({
			top:0,
			left:0,
			bottom:0,
			width:$$.platformWidth*_args.views.length
		});

		for (var i = 0, l = views.length; i<l; i++) {
			// Creating a scroll view for each app view
			var newView = Ti.UI.createScrollView({
				//showVerticalScrollIndicator:true,
				scrollType: 'vertical',
				top:0,
				bottom:0,
				left:$$.platformWidth*i,
				width:$$.platformWidth,
				contentWidth:$$.platformWidth
			});


			// Hide tabs when the content is clicked
			newView.addEventListener('click',function(e){
				
				//Ti.App.fireEvent("app:msg",{msg:"e.y:" + e.y + "\ncontentHeight" + contentHeight + "\n$$.platformHeight:" + $$.platformHeight + "\nt:" + t});
				
				// Show tabs when the content is clicked
				if (S.ui.tabsHidden == true){
					//Ti.App.fireEvent("app:tabsShow");
					//Ti.App.fireEvent("app:headerShow");
				}
				
			});	
						
			
			// Hide tabs when the content is scrolled
			newView.addEventListener('scroll',function(e){
				
				// Getting the content height
				var contentHeight = (e.source.children[0]) ? e.source.children[0].size.height : $$.platformHeight;
				var t = contentHeight - $$.platformHeight;
				
				//Ti.App.fireEvent("app:msg",{msg:"e.y:" + e.y + "\ncontentHeight" + contentHeight + "\n$$.platformHeight:" + $$.platformHeight + "\nt:" + t});
				
				// Hide tabs only when the content is scrolled more than 0 (e.y > 0)
				if ((e.y*1 > S.ui.layout.tabSize && e.y*1 < t) && S.ui.tabsHidden == false){
					Ti.App.fireEvent("app:tabsHide");
					Ti.App.fireEvent("app:headerHide");
				} 
				
				// Show tabs when the content is scrolled to the bottom limits
				if ((e.y*1 >= t || e.y*1 <= S.ui.layout.tabSize) && S.ui.tabsHidden == true){
					Ti.App.fireEvent("app:tabsShow");
					Ti.App.fireEvent("app:headerShow");
				}
				
			});		

	
						
			// Adding app view into newly created scroll view
			newView.add(views[i]);
			// Adding the scroll view into temporary container
			container.add(newView);

		}
				
		// Adding all to root
		root.add(container);
		
		// Set currently visible index
		root.addEventListener('changeIndex', function(e) {
			var leftValue = $$.platformWidth*e.idx*-1;
			container.animate({
				duration:$$.animationDuration,
				left:leftValue
			});
		});
		
		return root;
	};
}());
Ti.include("/struct/classes/auth.js");

Ti.include("/struct/ui/styles.js");
Ti.include("/struct/ui/applicationwindow.js");